package com.onlineClass.edu.aop;

import com.onlineClass.edu.base.BaseApiController;
import com.onlineClass.edu.base.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author 邓辉
 * @ClassName LogExceptionAop
 * @date 2024-04-30 20:56
 * aop环绕通知对异常进行统一日志记录
 */
@Aspect
@Component
@Slf4j
public class LogExceptionAop extends BaseApiController {
    //切点
    @Pointcut("execution(public * com.onlineClass.edu.controller..*.*(..))")
    private void pt() {
    }

    @Around("pt()")
    public Object logRecord(ProceedingJoinPoint pjp) throws Throwable {
        try {
            return pjp.proceed();
        } catch (Throwable e) {
            log.error("<error{}>", e);
            return setResultError();
        }
    }

}
